<?php
class Crm_model extends CI_Model {
	
	public function __construct ()
	{
		$this->load->database();
	}
	
	public function get_user($email = "", $password = "")
	{
		$query = $this->db->get_where('qs_user', array('email'=>$email, 'password'=>$password, 'activationkey'=>''));	
		return $query->row_array();	
	}
	
	public function get_company_info()
	{	
		$this->db->select('*');
		$this->db->from('qs_contact');
		$this->db->join('qs_business_archive', 'qs_contact.company_id = qs_business_archive.company_id');
		$query = $this->db->get();
		return $query->result_array();
	}
	
	public function get_company_detail($company_name)
	{
		$sql = "select * 
				FROM qs_contact c, qs_business_archive b 
				WHERE c.company_id = b.company_id 
				AND b.company_name = ?";
		$query = $this->db->query($sql, array($company_name));
		return $query->row_array();
	}
	
	public function register_user($user_info = array())
	{
		$this->db->insert('qs_user', $user_info);
		return ;
	}
	
	public function get_all_user()
	{
		$query = $this->db->get('qs_user');
		return $query->result_array();
	}
	
	public function update_user($id)
	{
		$data = array(
					'activationKey' => '',
					'status' => 'activated'
				);
		$this->db->where('id',$id);
		$this->db->update('qs_user', $data);
		return ;
	}
}